/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validator;

import Model.UserBean;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
/**
 *
 * @author dnorji
 */
@FacesValidator("Validator.AdminValidator")
public class AdminValidator implements Validator {
    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            UserBean userBean = (UserBean) FacesContext.getCurrentInstance().
                    getExternalContext().getSessionMap().get("userBean");

            if(userBean.isIsAdmin()){
                FacesMessage msg = new FacesMessage("Admins cannot leave households.");
                throw new ValidatorException(msg);
            }
    }
}